package com.cqvie.dao;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import com.cqvie.model.Classes;

@Repository("classDao")
public class ClassDao {
	@Resource
	private SessionFactory sessionFactory;

	// 根据ID来查询班级
	@SuppressWarnings("unchecked")
	public List<Classes> selectClassByID(String i) {
		Session session = sessionFactory.getCurrentSession();
		String hql = "from Classes classes where classes.classID=?";
		Query query = session.createQuery(hql);
		query.setString(0, i);
		List<Classes> listClass = query.list();
		if (listClass.size() >= 1) {
			return listClass;
		} else
			return null;
	}
	
	public Classes GetClasses(String id){
		Session session=sessionFactory.getCurrentSession();
		Classes classes=(Classes)session.get(Classes.class, id);
		return classes;
	}
	
	//添加班级信息
	public void addClass(Classes c){
		Session session=sessionFactory.getCurrentSession();
		session.save(c);
	}
}
